package com.yl.wanandroid_mvvm_kotlin_jetpack

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.tencent.mmkv.MMKV
import com.yl.common.util.AppUtil
import com.yl.home.di.homeModule
import com.yl.login.di.loginModule
import com.yl.navigation.di.navigationModule
import com.yl.navigation.di.treeModule
import com.yl.projects.di.projectModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext
import org.koin.core.logger.Level

class MyApp : Application() {

    private val modules =
        mutableListOf(
            loginModule,
            homeModule,
            navigationModule,
            treeModule,
            projectModule/*,mimeModule*/
        )

    override fun onCreate() {
        super.onCreate()

        //设置全局appliction
        AppUtil.setApplication(this)

        //路由
        initRouter()

        //初始化sp
        initMMKV()

        initKoin()
    }

    private fun initRouter() {
        if (BuildConfig.DEBUG) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
    }


    private fun initMMKV() {
        MMKV.initialize(this)
    }

    private fun initKoin() {
        GlobalContext.startKoin {
            androidLogger(Level.NONE)
            androidContext(this@MyApp)
            modules(modules)
        }
    }
}